package com.mofang.ticketing.common.core.util;

import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.Mode;
import cn.hutool.crypto.Padding;
import cn.hutool.crypto.symmetric.AES;

/**
 * @author LGC
 */
public class AESUtils {

    /**
     * 加密秘钥
     */
    private static final String SECRET = "secret8c0f1f4bf075b1";

    /**
     * IV
     */
    private static final String IV = "iv8c0f1f4bf075b1";

    /**
     * AES加密
     */
    public static String encrypt(String content) {
        if (StrUtil.isBlank(content)) {
            return "";
        }
        AES aes = new AES(Mode.CBC, Padding.PKCS5Padding,
                SECRET.getBytes(),
                IV.getBytes());
        return aes.encryptHex(content);
    }

    /**
     * AES解密
     */
    public static String decrypt(String ciphertext) {
        if (StrUtil.isBlank(ciphertext)) {
            return "";
        }
        AES aes = new AES(Mode.CBC, Padding.PKCS5Padding,
                SECRET.getBytes(),
                IV.getBytes());
        return aes.decryptStr(ciphertext);
    }


    public static void main(String[] args) {
        System.out.println(encrypt("123456"));
//        System.out.println(pwdDecrypt("798c0f1f4bf075b13e6735b869a7e7b8a1dac3c016171f7bae5125517e2ab15b"));
    }

}


